#include <bits/stdc++.h>

#define N 1010

using namespace std;

int n;
string op[N], ad[N];

bool ok (string s)
{
	int a = 0, b = 0, c = 0, d = 0, e = 0;
	int pos = 0;
	if (s[pos] <= '0' && s[pos] > '9') return 0;
	while(s[pos] >= '0' && s[pos] <= '9') a = a * 10 + s[pos] - '0', pos ++;
	if (a > 255) return 0;
	if (s[pos] != '.') return 0; 
	pos ++; 
	if (s[pos] <= '0' && s[pos] > '9') return 0;
	while(s[pos] >= '0' && s[pos] <= '9') b = b * 10 + s[pos] - '0', pos ++;
	if (b > 255) return 0;
	if (s[pos] != '.') return 0; 
	pos ++; 
	if (s[pos] <= '0' && s[pos] > '9') return 0;
	while(s[pos] >= '0' && s[pos] <= '9') c = c * 10 + s[pos] - '0', pos ++;
	if (c > 255) return 0;
	if (s[pos] != '.') return 0; 
	pos ++; 
	if (s[pos] <= '0' && s[pos] > '9') return 0;
	while(s[pos] >= '0' && s[pos] <= '9') d = d * 10 + s[pos] - '0', pos ++;
	if (d > 255) return 0;
	if (s[pos] != ':') return 0; 
	pos ++; 
	if (s[pos] <= '0' && s[pos] > '9') return 0;
	while(s[pos] >= '0' && s[pos] <= '9') e = e * 10 + s[pos] - '0', pos ++;
	if (e > 65535) return 0;
	return 1;
}

int main (void)
{
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i ++)
		cin >> op[i] >> ad[i];
	for (int i = 1; i <= n; i ++)
		if (ok(ad[i]))
		{
			if (op[i] == "Server")
			{
				bool b = 1;
				for (int j = 1; j < i; j ++)
					if (op[j] == "Server" && ad[i] == ad[j]) 
					{
						printf("FAIL\n");
						b = 0;
						break;
					}
				if (b) printf("OK\n");
			}
			else if (op[i] == "Client")
			{
				bool b = 1;
				for (int j = 1; j < i; j ++)
					if (op[j] == "Server" && ad[i] == ad[j]) 
					{
						printf("%d\n", j);
						b = 0;
						break;
					}
				if (b) printf("FAIL\n");
			}
		}
		else printf("ERR\n");
	return 0;
}
